﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TGBTech.Core.Models.ChungTu;

namespace TGBTech.Core.Models.Models.BaoCao.SoNhatKyChiThuTienModel
{
    public class SoNhatKyChiThuTienFactory
    {
        public static String TAIKHOAN_KHAC = "KHAC";
        //create record of report by data input
        public static SoNhatKyChiThuTienModel getModel( ref SoNhatKyChiThuTienModel model, Data data, Boolean isChi, String strTaiKhoans) {
            //init model with data
            if (model == null)
            {
                model = new SoNhatKyChiThuTienModel();
            }
            model.SoHieuCT = data.SoCT;
            model.NgayThangCT = data.NgayCT;
            model.SoTien = data.SoTien;
            model.DienGiai = data.DienGiaiNo;
            if (model.TaiKhoanDoiUng == null)
            {
                model.TaiKhoanDoiUng = new Dictionary<string, decimal>();
            }
            //taikhoan string
            String strTaiKhoan;
            //if model of SoChiTien
            if (isChi)
            {
                strTaiKhoan = data.TaiKhoanNoId.Substring(0, 3); 
            }
            else // if model of SoThuTien
            {
                strTaiKhoan = data.TaiKhoanCoId.Substring(0, 3);
            }
            //check taikhoan is khac
            if (!strTaiKhoans.Contains(strTaiKhoan))
            {
                model.TaiKhoanDUKhac = (String)strTaiKhoan.Clone();
                strTaiKhoan = TAIKHOAN_KHAC;

            }
            model.TaiKhoanDoiUng.Add(strTaiKhoan, data.SoTien);
            return model;
        }
    }
}
